package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.WmsInventoryLog;
import com.ruoyi.system.service.IWmsInventoryLogService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 库存操作日志Controller
 * 
 * @author ruoyi
 * @date 2025-06-18
 */
@Controller
@RequestMapping("/system/log")
public class WmsInventoryLogController extends BaseController
{
    private String prefix = "system/log";

    @Autowired
    private IWmsInventoryLogService wmsInventoryLogService;

    @RequiresPermissions("system:log:view")
    @GetMapping()
    public String log()
    {
        return prefix + "/log";
    }

    /**
     * 查询库存操作日志列表
     */
    @RequiresPermissions("system:log:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WmsInventoryLog wmsInventoryLog)
    {
        startPage();
        List<WmsInventoryLog> list = wmsInventoryLogService.selectWmsInventoryLogList(wmsInventoryLog);
        return getDataTable(list);
    }

    /**
     * 导出库存操作日志列表
     */
    @RequiresPermissions("system:log:export")
    @Log(title = "库存操作日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WmsInventoryLog wmsInventoryLog)
    {
        List<WmsInventoryLog> list = wmsInventoryLogService.selectWmsInventoryLogList(wmsInventoryLog);
        ExcelUtil<WmsInventoryLog> util = new ExcelUtil<WmsInventoryLog>(WmsInventoryLog.class);
        return util.exportExcel(list, "库存操作日志数据");
    }

    /**
     * 新增库存操作日志
     */
    @RequiresPermissions("system:log:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存库存操作日志
     */
    @RequiresPermissions("system:log:add")
    @Log(title = "库存操作日志", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WmsInventoryLog wmsInventoryLog)
    {
        return toAjax(wmsInventoryLogService.insertWmsInventoryLog(wmsInventoryLog));
    }

    /**
     * 修改库存操作日志
     */
    @RequiresPermissions("system:log:edit")
    @GetMapping("/edit/{logId}")
    public String edit(@PathVariable("logId") Long logId, ModelMap mmap)
    {
        WmsInventoryLog wmsInventoryLog = wmsInventoryLogService.selectWmsInventoryLogByLogId(logId);
        mmap.put("wmsInventoryLog", wmsInventoryLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存库存操作日志
     */
    @RequiresPermissions("system:log:edit")
    @Log(title = "库存操作日志", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WmsInventoryLog wmsInventoryLog)
    {
        return toAjax(wmsInventoryLogService.updateWmsInventoryLog(wmsInventoryLog));
    }

    /**
     * 删除库存操作日志
     */
    @RequiresPermissions("system:log:remove")
    @Log(title = "库存操作日志", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wmsInventoryLogService.deleteWmsInventoryLogByLogIds(ids));
    }
}
